#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

int main()
{
    int fd = open("bite", O_RDWR | O_CREAT, 0644);
    if(fd == -1)
    {
        perror("文件打开失败");
        exit(1);
    }

    const char *data = "i like linux!";
    ssize_t written = write(fd, data, strlen(data));
    if(written ==-1)
    {
        perror("写入失败");
        close(fd);
        exit(1);
    }

    off_t pos = lseek(fd, 0, SEEK_SET);
    if(pos == -1)
    {
        perror("lseek失败");
        close(fd);
        exit(1);
    }

    char buffer[50];
    ssize_t readc = read(fd, buffer, sizeof(buffer));
    if(readc == -1)
    {
        perror("读取失败");
        close(fd);
        exit(1);
    }
    else
    {
        buffer[readc] = '\0';
        printf("读取内容：%s\n", buffer);
    }

    close(fd);

    return 0;
}




